home *** CD-ROM | disk | FTP | other *** search
- import com.siemens.mp.io.File;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import javax.microedition.io.Connector;
- import javax.microedition.io.StreamConnection;
-
- public class Globals {
- public static String fileExtension = ".cst";
- public static String tmpFileExtension = ".tmp";
- public static String POP3_USER = "USER ";
- public static String POP3_PASS = "PASS ";
- public static String POP3_LIST = "LIST";
- public static String POP3_STAT = "STAT";
- public static String POP3_RETR = "RETR ";
- public static String POP3_UIDL = "UIDL";
- public static String POP3_TOP = "TOP ";
- public static String POP3_DELE = "DELE ";
- public static String POP3_QUIT = "QUIT";
- public static String RESPONSE_OK = "+OK";
- public static String RESPONSE_ERR = "-ERR";
- public static String RESPONSE_END = ".";
- public static String SEND_HELO = "HELO";
- public static String SEND_QUIT = "QUIT";
- public static String SEND_MAILFROM = "MAIL FROM:";
- public static String SEND_RCPTTO = "RCPT TO:";
- public static String SEND_DATA = "DATA";
- public static String CONN_OK = "220";
- public static String HELO_OK = "250";
- public static String FROM_OK = "250";
- public static String TO_OK = "250";
- public static String DATA_OK = "354";
- public static String OUT_OK = "250";
- public static String QUIT_OK = "221";
- public static int maxMsgSize = 2048;
- public static byte[] byteArray;
- public static int bodyStart;
- public static int bodyLen;
- public static Account account;
- public static StreamConnection conn;
- // $FF: renamed from: in java.io.DataInputStream
- public static DataInputStream field_0;
- public static DataOutputStream out;
- public static File file;
- public static File file2;
- public static int fileDesc;
- public static int fileDesc2;
-
- static {
- byteArray = new byte[maxMsgSize];
- file = new File();
- file2 = new File();
- }
-
- public static boolean connectToServer(boolean var0) {
- try {
- if (var0) {
- conn = (StreamConnection)Connector.open("socket://" + account.popHost + ":" + account.popPort);
- } else {
- conn = (StreamConnection)Connector.open("socket://" + account.smtpHost + ":" + account.smtpPort);
- }
-
- out = conn.openDataOutputStream();
- field_0 = conn.openDataInputStream();
- if (var0) {
- if (!waitForMessage(RESPONSE_OK, var0)) {
- return false;
- } else {
- writeLine(POP3_USER + account.username);
- if (!waitForMessage(RESPONSE_OK, var0)) {
- return false;
- } else {
- writeLine(POP3_PASS + account.password);
- return waitForMessage(RESPONSE_OK, var0);
- }
- }
- } else if (!waitForMessage(CONN_OK, var0)) {
- return false;
- } else {
- writeLine(SEND_HELO + " MicroMail");
- return waitForMessage(HELO_OK, var0);
- }
- } catch (Exception var2) {
- ((Throwable)var2).printStackTrace();
- return false;
- }
- }
-
- public static boolean disconnectFromServer(boolean var0) {
- try {
- if (var0) {
- writeLine(POP3_QUIT);
- waitForMessage(RESPONSE_OK, var0);
- } else {
- writeLine(SEND_QUIT);
- waitForMessage(QUIT_OK, var0);
- }
-
- if (out != null) {
- out.close();
- out = null;
- }
-
- if (field_0 != null) {
- field_0.close();
- field_0 = null;
- }
-
- if (conn != null) {
- conn.close();
- conn = null;
- }
-
- System.gc();
- return true;
- } catch (Exception var2) {
- MicroMail.printInfo(var2.getClass().getName() + ": " + ((Throwable)var2).getMessage());
- ((Throwable)var2).printStackTrace();
- return false;
- }
- }
-
- public static void disposeAccount() {
- account = null;
- }
-
- public static int indexOf(char var0, int var1, int var2) {
- int var3;
- for(var3 = var1; var0 != byteArray[var3] && var3 < var2; ++var3) {
- }
-
- return var3 >= var2 ? -1 : var3;
- }
-
- public static int indexOf(String var0, int var1, int var2) {
- int var5 = var1;
-
- for(int var4 = 0; var5 < var2; ++var5) {
- var5 = indexOf(var0.charAt(0), var5, var2);
- if (var5 <= -1) {
- return -1;
- }
-
- for(var4 = 0; var4 < var0.length() && var0.charAt(var4) == byteArray[var5 + var4]; ++var4) {
- }
-
- if (var4 == var0.length()) {
- return var5;
- }
- }
-
- return -1;
- }
-
- public static int makeInt(int var0, int var1) {
- int var2 = 0;
-
- for(int var3 = var0; var3 <= var1; ++var3) {
- var2 = var2 * 10 + byteArray[var3] - 48;
- }
-
- return var2;
- }
-
- public static int readHeader() {
- int var0 = -1;
- int var1 = 0;
-
- do {
- ++var0;
-
- try {
- var1 = field_0.read();
- } catch (Exception var2) {
- }
-
- byteArray[var0] = (byte)var1;
- } while(var1 != 46 || byteArray[var0 - 1] != 10);
-
- return var0;
- }
-
- public static int readLine() {
- int var0 = readLine(-1);
- return var0;
- }
-
- public static int readLine(int var0) {
- boolean var1 = false;
- boolean var2 = false;
- int var3 = 0;
- int var4 = 0;
-
- do {
- try {
- var4 = field_0.read();
- } catch (IOException var5) {
- }
-
- switch (var4) {
- case -1:
- var1 = true;
- break;
- case 10:
- ++var3;
- ++var0;
- if (var2) {
- var1 = true;
- } else {
- byteArray[var0] = 10;
- }
- break;
- case 13:
- var2 = true;
- ++var3;
- break;
- default:
- ++var3;
- if (var2) {
- ++var0;
- byteArray[var0] = 13;
- var2 = false;
- }
-
- ++var0;
- byteArray[var0] = (byte)var4;
- }
- } while(!var1);
-
- if (var3 == 0) {
- return -1;
- } else if (byteArray[0] == 46) {
- return -1;
- } else {
- return var0;
- }
- }
-
- public static void setAccount(Account var0) {
- account = var0;
- }
-
- public static boolean startsWith(char var0, int var1) {
- return var0 == byteArray[var1];
- }
-
- public static boolean startsWith(String var0, int var1) {
- int var2 = var0.length();
-
- for(int var3 = 0; var3 < var2; ++var3) {
- if (var0.charAt(var3) != byteArray[var3 + var1]) {
- return false;
- }
- }
-
- return true;
- }
-
- protected static boolean waitForMessage(String var0, boolean var1) {
- while(readLine() > -1) {
- if (startsWith(var0, 0)) {
- return true;
- }
-
- if (var1) {
- if (!startsWith(RESPONSE_ERR, 0)) {
- continue;
- }
-
- return false;
- }
-
- return false;
- }
-
- return false;
- }
-
- public static void writeBodyLine(String var0) {
- try {
- out.writeUTF(var0);
- out.write("\r\n".getBytes());
- } catch (Exception var3) {
- ((Throwable)var3).printStackTrace();
- }
-
- }
-
- public static void writeLine(String var0) {
- try {
- var0 = var0 + "\r\n";
- out.write(var0.getBytes());
- } catch (Exception var2) {
- ((Throwable)var2).printStackTrace();
- }
-
- }
- }
-